package weifei.live.simulation.entity;


import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.springframework.stereotype.Repository;


@Data
@EqualsAndHashCode(callSuper = true)
@TableName("user")
@Repository
public class User extends Model<User>
{
    @Getter
    public enum Column
    {
        ID("id"),
        WXID("wxid"),
        AvatarID("avatar_id"),
        Nickname("nickname"),
        Username("username"),
        Password("password"),
        Email("email"),
        Phone("phone"),
        RegisterTime("register_time"),
        LastLoginTime("last_login_time"),
        State("state");


        final String name;

        Column(String name) { this.name = name; }
    }


    public enum State
    {
        Offline(1, "离线"),
        Online(2, "在线");

        @EnumValue
        final int id;
        @Getter
        final String name;
        State(int id, String name) { this.id = id;this.name = name; }
        public int getID() { return this.id; }
    }


    @TableId
    private Integer id = 0;
    private String wxid;
    private Integer avatarId;
    private String nickname;
    @NotBlank @NotNull
    private String username;
    @NotBlank @NotNull
    private String password;

    private String email;
    private String phone;

    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private java.util.Date registerTime;
    @JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private java.util.Date lastLoginTime;
    private State state;


    /** 做数据库修改用 */
    public User() {}
    /**
     * selectByID
     * deleteByID
     * 使用
     * */
    public User(int userId) { this.id = userId; }
    public User(
            String nickname,
            String username,
            String password
    )
    {
        this.nickname = nickname;
        this.username = username;
        this.password = password;
    }


    public User(
            String username,
            String password,
            String email,
            String phone
        )
    {
        this.username = username;
        this.password = password;
        this.email = email;
        this.phone = phone;
    }


    public String getAvatarBase64()
    {
        return new Avatar(this.avatarId).selectById().getContent();
    }
}


